package com.example.hyw.szysteam.presenter;

import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.POJO.HttpReview;
import com.example.hyw.szysteam.POJO.Review;
import com.example.hyw.szysteam.model.MistakeBookModel;
import com.example.hyw.szysteam.view.MistakeBookActivity;

import java.util.ArrayList;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by HYW on 2018/7/12.
 */

public class MistakeBooksPresenter {
    MistakeBookModel mistakeBookModel=new MistakeBookModel();
    MistakeBookActivity mistakeBookActivity;

    public MistakeBooksPresenter(MistakeBookActivity mistakeBookActivity) {
        this.mistakeBookActivity = mistakeBookActivity;
    }

    public void getMistakeBooks(String email){
        mistakeBookModel.getmistakebooks(email)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<ArrayList<Review>>>() {
                    @Override
                    public void accept(HttpResult<ArrayList<Review>> arrayListHttpResult) throws Exception {
                        ArrayList<Review> reviews=arrayListHttpResult.getContent();
                        mistakeBookActivity.initListView(reviews);
                    }
                });
    }
}
